package com.heima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.admin.mapper.ApUserRealnameMapper;
import com.heima.admin.service.ApUserRealnameService;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.dtos.AuthDto;
import com.heima.model.user.pojos.ApUserRealname;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ApUserRealnameServiceImpl extends ServiceImpl<ApUserRealnameMapper, ApUserRealname>
 implements ApUserRealnameService {

    /***
     * 用户认证列表查询
     * @param authDto
     * @return
     */
    @Override
    public ResponseResult ApUserList(AuthDto authDto) {
        //检查参数
        if(authDto == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID,"参数不能为空");
        }

        //分页检查
        authDto.checkParam();

        //根据分页状态分页查询
        LambdaQueryWrapper<ApUserRealname> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(authDto.getStatus() != null){
            lambdaQueryWrapper.eq(ApUserRealname::getStatus,authDto.getStatus());
        }

        //分页显示
        IPage pageParam = new Page(authDto.getPage(),authDto.getSize());
        IPage page = page(pageParam,lambdaQueryWrapper);


        //返回结果
        PageResponseResult responseResult = new PageResponseResult(authDto.getPage(),authDto.getSize(),
                (int) page.getTotal());
        responseResult.setData(page.getRecords());

        return responseResult;
    }
}
